package com.example.f_code;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class LoginActivity extends AppCompatActivity {
    private EditText et_user, et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);

        et_user = findViewById(R.id.et_user);
        et_password = findViewById(R.id.et_password);

        // 登录按钮点击事件
        Button btn_login = findViewById(R.id.btn_login);
        btn_login.setOnClickListener(v -> login());

        // 注册
        TextView tv_register = findViewById(R.id.tv_register);
        tv_register.setOnClickListener(v -> {
            startActivity(new Intent(this, RegisterActivity.class));
        });
    }

    private void login() {
        String user = et_user.getText().toString();
        String password = et_password.getText().toString();
        if (user.isEmpty() || password.isEmpty()) {
            Toast.makeText(LoginActivity.this, "请输入用户名和密码", Toast.LENGTH_SHORT).show();
        } else if (user.equals("admin") && password.equals("123456")) {
            // 登录成功
            startActivity(new Intent(this, HomeActivity.class));
        } else {
            // 登录失败
            Toast.makeText(LoginActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
        }
    }
}
